﻿using RimWorld;
using Verse;

namespace RimZombieGirl
{
    public class HediffComp_CurseDisease : HediffComp
    {
        private int lastDiseaseDay = -1;

        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);

            if (Pawn.Dead || !Pawn.Spawned) return;

            // 每天只检查一次
            if (Find.TickManager.TicksGame % 60000 != 0)
                return;

            int currentDay = GenLocalDate.DayOfYear(parent.pawn.Map);
            if (lastDiseaseDay == currentDay)
                return;

            lastDiseaseDay = currentDay;

            if (Rand.Value > 0.05f)
                return;

            HediffDef[] possibleDiseases = new HediffDef[]
            {
                HediffDefOf.Carcinoma,  // 癌症
                HediffDef.Named("Flu"),        // 流感
                HediffDefOf.FoodPoisoning,
                HediffDef.Named("HeartArteryBlockage"),
                HediffDef.Named("Asthma")
            };

            HediffDef chosen = possibleDiseases.RandomElement();
            Pawn.health.AddHediff(chosen);

            Messages.Message($"{Pawn.LabelShort} 因诅咒染上了 {chosen.label}。".Translate(), Pawn, MessageTypeDefOf.NegativeHealthEvent);
        }
    }

    public class HediffCompProperties_CurseDisease : HediffCompProperties
    {
        public HediffCompProperties_CurseDisease()
        {
            this.compClass = typeof(HediffComp_CurseDisease);
        }
    }
}
